using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for DesignerLogAdaptor.
	/// </summary>
	public class DesignerLogAdaptor : Adaptor, IRefreshable, IClearable
	{
    private DesignerLog log;
		public DesignerLogAdaptor(DesignerLog log)
		{
      this.log = log;
		}

    public override void AddChildren(TreeNode node)
    {
      int numberToShow = log.Count;
      if (numberToShow > 100)
        numberToShow = 100;
      for (int i = 0; i < numberToShow; i++)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(
          new DesignerLogEntryAdaptor(log[i]));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 11;
      }
    }

    public override string Text
    {
      get
      {
        return "Designer Log (" + log.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      DesignerLogControl control = new DesignerLogControl();
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      control.LoadDesignerLog(log);
      return control;
    }

    public override object Object
    {
      get
      {
        return log;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      log.Refresh();
    }

    #endregion
    #region IClearable Members

    public void Clear()
    {
      log.Clear();
    }

    #endregion
  }
}
